package org.agent.aigccore.basic.model.request;

import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.Setter;
import org.agent.aigccore.basic.enums.ExtAttributeEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/**
 * @author: mofan
 * @date: 2023/07/05 14:07
 */
@Setter
@Getter
public class BaseRequest implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 扩展信息
     *
     * @see ExtAttributeEnum
     */
    private Map<String, String> externalData = Maps.newHashMap();

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    /**
     * 添加扩展信息
     *
     * @param key
     * @param value
     */
    private void addExt(String key, String value) {
        if (StringUtils.isNotBlank(value)) {
            if (Objects.isNull(externalData)) {
                externalData = Maps.newHashMap();
            }
            externalData.put(key, value);
        }
    }

    /**
     * 添加扩展信息
     *
     * @param key
     * @param value
     */
    private void addExt(ExtAttributeEnum key, String value) {
        addExt(key.name(), value);
    }

    /**
     * 获取扩展信息
     *
     * @param key
     * @return
     */
    private String getExt(String key) {
        if (Objects.nonNull(externalData)) {
            return externalData.get(key);
        }
        return null;
    }

    /*
     * 获取扩展信息
     */
    private String getExt(ExtAttributeEnum key) {
        return getExt(key.name());
    }
}
